﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using xplang.run;
using xplang.abstractions;
using System.Diagnostics;

namespace xplang.statements
{
  [DebuggerDisplay("{statements}")]
  public class StatementBlock : Statement
  {

    public readonly List<Expression> statements = new List<Expression>();

    public override Value doIt(Value[] heap, ref FlowState state)
    {
      int n = statements.Count;
      for (int i = 0; i < n; i++)
      {
        statements[i].doIt(heap, ref state);
        if (state != FlowState.Normal)
          return null;
      }
      return null;
    }

    public override bool isBlock()
    {
      return true;
    }
    //public override void save(Scope scope, SourceBuilder target)
    //{
    //    if (braces)
    //        target.writeln("{");
    //    target.incIdent();
    //    foreach (Statement stmt in statements)
    //        stmt.save(scope, target);
    //    target.decIdent();
    //    if (braces)
    //        target.writeln("}");
    //}

    //public override void toCSharp(Scope scope, SourceBuilder target)
    //{
    //    if (braces) 
    //        target.writeln("{");
    //    target.incIdent();
    //    foreach (Statement stmt in statements)
    //        stmt.toCSharp(scope,target);
    //    target.decIdent();
    //    if (braces)
    //        target.writeln("}");
    //}

    //public override void toJavaScript(Scope scope, SourceBuilder target)
    //{
    //    if (braces)
    //        target.writeln("{");
    //    target.incIdent();
    //    foreach (Statement stmt in statements)
    //        stmt.toJavaScript(scope, target);
    //    target.decIdent();
    //    if (braces)
    //        target.writeln("}");
    //}
  }
}
